﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Threading;

namespace StProxy
{
    public partial class frmSplash : Form
    {
        private int i = 0;
        public frmSplash()
        {
            InitializeComponent();
        }

        private void frmSplash_Load(object sender, EventArgs e)
        {
            this.Visible = false;
            this.FormBorderStyle = FormBorderStyle.None;
            Bitmap bitMap = StProxy.Properties.Resources.Logo;
            this.Size = bitMap.Size;
            this.BackgroundImage = bitMap;
            this.TransparencyKey = Color.Blue;
            this.Left -= 240;
            this.Top -= 100;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.TopMost = true;

            CreatAboutInfo();
            this.Visible = true;
        }

        private void CreatAboutInfo()
        {
            this.labelProductName.Text = AssemblyProduct + String.Format(" V {0}", AssemblyVersion);
            this.labelCopyright.Text = AssemblyCopyright;
            this.labelDescription.Text = AssemblyDescription;
        }

        #region 程序集属性访问器

        public string AssemblyTitle
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title != "")
                    {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }

        public string AssemblyVersion
        {
            get
            {
                return Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
        }

        public string AssemblyDescription
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }

        public string AssemblyProduct
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }

        public string AssemblyCopyright
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }

        public string AssemblyCompany
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }
        #endregion

        private void timerSplash_Tick(object sender, EventArgs e)
        {
            i++;
            if (i > 2)
            {
                OpenMainForm();
            }
        }

        private void OpenMainForm()
        {
            this.timerSplash.Enabled = false;
            Form frmMain = new frmMain();

            this.Hide();
            frmMain.ShowDialog();
        }

        private void frmSplash_Click(object sender, EventArgs e)
        {
            OpenMainForm();
        }
    }
}
